<?php 
define('IN_WONDERSHARE', true);
header("Content-type:text/html;charset=utf-8");
require('../includes/init.php');
require('./classes/control/control_support_right_recommend.php');
class Support_Right_Recommend
{
	var $support_right_recommend_c;
	/**
	* @ 构造函数,实例化Support_Right_Recommend
	* @ __construct
	*/
	public function __construct()
	{
		$this->support_right_recommend_c = new SupportRightRecommendControl();
	}

	/**
	* 函数index,返回默认列表
	* @param  NULL
	* @return  string
	*/
	function index()
	{
		$web_type = (int)$_GET['web_type'];
		$recommend_info = array();
		if(!empty($web_type))
		{
			$recommend_info = $this->support_right_recommend_c->get_recommend_list($web_type);
		}
		$GLOBALS['smarty']->assign('web_type',$web_type);
		$GLOBALS['smarty']->assign('web_info',   get_web_info($web_type));
		$GLOBALS['smarty']->assign('recommend_info',$recommend_info);
		$GLOBALS['smarty']->display('support_right_recommend_index.htm'); 
	}
	/**
	* 函数edit,Product Support栏目左侧链接管理编辑页
	* @param  NULL
	* @return  string
	*/
	public function edit()
	{	
		$web_type = (int)$_REQUEST['web_type'];
		$two_cat_id = (int)$_REQUEST['two_cat_id'];
		$category_info = array();
		
		if($_POST['sub_from'])
		{
			$insert_array = array(
			'two_cat_id'=>$two_cat_id,
			'topic_cat_id'=>(int)$_POST['topic_cat_id'],
			'recommend_article'=>trim($_POST['recommend_id']),
			'web_type' => $web_type
			);
			
			$this->support_right_recommend_c->operate_select_elements('del_support_right',(int)$_POST['topic_cat_id']);
			$this->support_right_recommend_c->operate_select_elements('del_support_right',(int)$_POST['start_topic_cat_id']);
			$affect_rows = $this->support_right_recommend_c->operate_right_recommend($insert_array);
			
			if(!empty($affect_rows))
			{
				echo  '<script type="text/javascript"> alert("编辑成功！");
				window.location.href="/wondershare/support_right_recommend.php?action=edit&web_type='.$web_type.'&two_cat_id='.$two_cat_id.'"; </script>';
				exit;
			}
		}
		
		if(!empty($two_cat_id) && !empty($two_cat_id))
		{
			$category_info = $this->support_right_recommend_c->get_category_info($web_type,$two_cat_id);
		}
		
		$GLOBALS['smarty']->assign('web_type',$web_type);
		$GLOBALS['smarty']->assign('web_info',   get_web_info($web_type));
		$GLOBALS['smarty']->assign('two_cat_id',$two_cat_id);
		$GLOBALS['smarty']->assign('category_info',$category_info);
		$GLOBALS['smarty']->display('support_right_recommend_info.htm');
	}

	/**
	* 弹出框显示
	* @param  NULL
	* @return  string
	*/
	public function article_list()
	{
		if($_GET['type'] == 'support_right')//当是选择文章checkbox触发的事件
		{
			$this->support_right_recommend_c->operate_select_elements($_GET['type'],trim($_GET['cat_id']),trim($_GET['start_value']),
			trim($_GET['operate_type']),trim($_GET['operate_id']));
		}elseif($_GET['type'] == 'del_support_right')//删除
		{
			$this->support_right_recommend_c->operate_select_elements($_GET['type'],trim($_GET['cat_id']));
		}
		else
		{
			$search_array = array
			(
			'web_type' => (int)trim($_REQUEST['web_type']),//网站类别
			'recommend_id' => trim($_REQUEST['recommend_id']),//已经选择的文章id组合
			'topic_cat_id' => (int)trim($_REQUEST['topic_cat_id'])//文章三级分类ID
			);
			if($_POST['sub_search'])
			{
				$search_array['ar_id'] = (int)trim($_REQUEST['re_ar_id']);//文章ID
				$search_array['ar_title'] = !empty($_POST['re_ar_title'])?trim($_POST['re_ar_title']):urldecode(trim($_GET['re_ar_title']));//文章标题
				$search_array['is_show'] = trim($_REQUEST['is_show']);//是否已选
				$search_array['type'] = 'search';//类型为搜索
			}
			$article_info  = $this->support_right_recommend_c->get_article_list($search_array);
			$GLOBALS['smarty']->assign('search_array',   $search_array);
			$GLOBALS['smarty']->assign('article_info',     $article_info['info']);
			$GLOBALS['smarty']->assign('check_strid',     $article_info['check_strid']);
			$GLOBALS['smarty']->display('support_article_list.htm'); 
		}
	}

}

$action    = $_REQUEST['action']; 
$support_right_recommend   = new Support_Right_Recommend;
if(method_exists($support_right_recommend, $action)) 
{
	$support_right_recommend->$action();
}else{
	$support_right_recommend->index();
}

?>
